{{template "admin/header.html"}}
<title>更新用户信息 - GPRESS</title>
<script type="text/javascript" src="{{basePath}}admin/js/sha3.min.js"></script>
{{template "admin/bodystart.html"}}
        <div class="layui-card layui-panel" style="height: 100%;">
          <div class="layui-card-header">
            更新用户信息
          </div>
          <div class="layui-card-body">
            <form class="layui-form" id="gpress-form" action="{{basePath}}admin/{{.UrlPathParam}}/update" method="POST">
				<div class="layui-form-item layui-col-md6">
				  <label class="layui-form-label">ID</label>
				  <div class="layui-input-block">
					<input type="hidden" name="id" id="id" value="{{.Data.Id}}" />
					
				    <input type="hidden" name="sortNo" id="sortNo" value=1 />
				    <input type="hidden" name="status" id="status" value=1 />
					<input type="text" class="layui-input" disabled value="{{.Data.Id}}" />
				  </div>
				</div>
				<div class="layui-form-item layui-col-md6">
					<label class="layui-form-label">账号</label>
					<div class="layui-input-block">
					  <input type="text" name="account" lay-verify="required" autocomplete="off" lay-reqtext="请填写账号" class="layui-input"  value="{{.Data.Account}}">
					</div>
				</div>

				<div class="layui-form-item layui-col-md6">
				  <label class="layui-form-label">密码</label>
				  <div class="layui-input-block">
					<input type="password" name="password" id="password" autocomplete="off" class="layui-input" lay-affix="eye" value="" >
				  </div>
				</div>
				<div class="layui-form-item layui-col-md6">
				  <label class="layui-form-label">用户名</label>
				  <div class="layui-input-block">
					<input type="text" name="userName" autocomplete="off" class="layui-input" value="{{.Data.UserName}}">
				  </div>
				</div>
				<div class="layui-form-item layui-col-md6">
					<label class="layui-form-label">区块链类型</label>
					<div class="layui-input-block">
						<select name="chainType" id="chainType">
							<option value="">请选择</option>
							<option value="XUPER">百度超级链</option>
							<option value="ETH">以太坊</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item layui-col-md6">
					<label class="layui-form-label">区块链地址</label>
					<div class="layui-input-block">
					  <input type="text" name="chainAddress" autocomplete="off" class="layui-input" value="{{.Data.ChainAddress}}">
					</div>
				</div>
				
				<div class="layui-form-item">
					<div class="layui-input-block">
					  <button type="submit" class="layui-btn layui-bg-blue" lay-submit lay-filter="gpress-form-ajax-update">提交修改</button>
					</div>
				</div>
			</form>
          </div>
        </div>
{{template "admin/bodyend.html"}}

<script>
	layui.use(function(){
	  var form = layui.form;
	  var layer = layui.layer;
	  var $ =layui.jquery;
	  $('#password').val("");
	  $("#chainType option[value='{{.Data.ChainType}}']").attr("selected", true);
	  form.render(); // 渲染全部表单


	  // 提交事件
	  form.on('submit(gpress-form-ajax-update)', function(data){
		
		var field = data.field; // 获取表单字段值
		field.sortNo=field.sortNo-0;
		field.status=field.status-0;
		let pwdValue=$('#password').val();
		if (pwdValue&&pwdValue!="") {
			field.password=sha3_512(pwdValue);
		}
		const form = document.getElementById('gpress-form');
		$.ajax({
			url:form.action,
			type:form.method,
			contentType: "application/json;charset=utf-8",
			dataType:"json",
			data:JSON.stringify(field),
			error:function(){
				layer.msg("修改错误,请重试!");
			},
			success:function(result){
				if (result.statusCode == 1) {
					layer.msg("修改成功!");
				}else{
					layer.msg("修改失败!");
				}
			}
		});
        return false; // 阻止默认 form 跳转

	  });
	});
	</script>
